import java.util.LinkedList;
import java.util.List;

public class Forum {
	private static Forum instance;
	private List<Topic> topics;

	private Forum() {
		topics = new LinkedList<Topic>();
	}
	
	public static Forum getInstance(){
		if (instance == null)
			instance = new Forum();
		return instance;
	}

	public void createTopic(Topic topic) {
		topics.add(topic);
	}
	
	public List<Topic> searchTopic(Profile profile){
		List<Topic> list = new LinkedList<Topic>();
		for(Topic t : topics){
			if (t.getProfile().match(profile)){
				list.add(t);
			}
		}
		return list;
		
	}

	public void removeTopic(Topic topic) {
		for (int x = 0; x<topics.size();x++) {
			if (topics.get(x).match(topic)) {
				topics.remove(x);
			}
		}
	}

	public List<Topic> getTopics() {
		return topics;
	}

}
